package site.teamo.biu.net.client.controller.model.server_management;

import lombok.Data;
import lombok.experimental.Accessors;
import site.teamo.biu.net.client.entity.ServerDO;
import site.teamo.biu.net.common.report.ReportResponse;
import site.teamo.biu.net.common.util.HostPort;

/**
 * @author haocongshun
 * @date 2023/06/13 9:41:58
 */
@Data
@Accessors(chain = true)
public class Server {
    private String id;
    private String name;

    private String token;

    private HostPort proxyServer;

    private long ping;

    private long accessTime;

    public Server fromReportResponse(ReportResponse response) {
        this.name = response.getName();
        this.proxyServer = response.getProxyServer();
        return this;
    }

    public Server fromServerDO(ServerDO serverDO) {
        this.id = serverDO.getId();
        this.name = "无法连接";
        this.proxyServer = HostPort.of("unknown", 0);
        this.ping = 999999;
        this.accessTime = serverDO.getCreateTime().getTime();
        return this;
    }
}
